<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" top="0" width="640px" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="30">
				<el-col :span="24">
					<el-form-item label="登录账号" prop="account">
						<sw-letter-input v-model="formData.account" placeholder="请输入登录账号，推荐使用邮箱或手机号注册账号"></sw-letter-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户名" prop="userName">
						<el-input v-model="formData.userName" placeholder="请输入用户名"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户昵称" prop="likeName">
						<el-input v-model="formData.likeName" placeholder="请输入用户昵称"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户部门" prop="deptId">
						<sw-depart-select v-model="formData.deptId" placeholder="请选择用户院系" style="width: 100%"></sw-depart-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户性别" prop="sex">
						<el-radio-group v-model="formData.sex" v-removeAriaHidden>
							<el-radio label="1">男</el-radio>
							<el-radio label="2">女</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="证件类型" prop="idType">
						<el-radio-group v-model="formData.idType" v-removeAriaHidden>
							<el-radio label="1">身份证</el-radio>
							<el-radio label="2">其他</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="证件号码" prop="idNumber">
						<el-input v-model="formData.idNumber" maxlength="18" placeholder="请输入用户名"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户电话" prop="phone">
						<sw-number-input v-model="formData.phone" maxLength="11" placeholder="请输入用户电话"></sw-number-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="用户系统类型" prop="userType" label-width="120px">
						<el-select v-model="formData.userType" placeholder="请选择用户系统类型" style="width: 100%">
							<el-option label="可登录" value="1"></el-option>
							<el-option label="可调用外部接口" value="2"></el-option>
							<el-option label="可登录+可调用外部接口" value="3"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="用户类型" prop="type">
						<el-radio-group v-model="formData.type">
							<el-radio v-for="(item, index) in dictData['USER_TYPE']" :key="index" :label="item.value">{{ item.msg }}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<template v-if="formData.type === '1'">
					<el-col :span="12">
						<el-form-item label="班级编号" prop="classNo">
							<el-input v-model="formData.classNo"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="专业编号" prop="major">
							<el-input v-model="formData.major"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="入学年月" prop="entranceDate">
							<el-date-picker v-model="formData.entranceDate" type="month" value-format="yyyy-MM-dd" placeholder="入学年月"></el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="生源地" prop="source">
							<el-input v-model="formData.source"></el-input>
						</el-form-item>
					</el-col>
				</template>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button @click="visible = false">取消</el-button>
			<el-button type="primary" @click="visible = false">确定</el-button>
		</template>
	</el-dialog>
</template>

<script>
import { mapGetters } from 'vuex';
import formMixins from '@/mixins/formMixins';
import nationSelect from '@/components/nationSelect';
import { userDetail, addedUser, updateUser } from '@/api/system/tbSysUser';
export default {
	mixins: [formMixins],
	consts: ['DEFAULT_PASSWORD'],
	components: { nationSelect },
	data() {
		return {
			formName: '用户',
			formRules: {
				account: [{ required: true, message: '请输入用户账号', trigger: 'blur' }],
				userName: [{ required: true, message: '请输入用户名称', trigger: 'blur' }],
				deptId: [{ required: true, message: '请选择用户院系', trigger: 'change' }]
			},
			defaultProps: {
				label: 'name',
				children: 'childList'
			}
		};
	},
	computed: {
		...mapGetters(['departTree']),
		detailData() {
			return eval(userDetail);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedUser : updateUser);
		},
		submitParams() {
			let params = { ...this.formData };
			params['systemKey'] = '1';
			params['picId'] = '-1';
			params['diskSpace'] = 0;
			params['password'] = rsa.rsaPublicData(this.dictData['DEFAULT_PASSWORD']);
			return params;
		}
	}
};
</script>
